package view;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;

public class StartBlock extends Block{
	private int id = -1;
	private Point controlPoint;
	
	public StartBlock(){
		super.setZId(0);
	}
	@Override
	public void draw(Graphics2D g) {
		Point point = super.getPoint();
		g.setColor(new Color(0.1F,0.8F,0.7F,0.5F));
		g.fillRoundRect(point.x, point.y, 60, 40, 10, 10);
		g.setColor(Color.BLACK);
		g.drawRoundRect(point.x, point.y, 60, 40, 10, 10);
		g.setFont(new Font("DialogInput", Font.PLAIN, 18));
		g.drawString("Start", point.x+4, point.y+22);
	}
	
	@Override
	public void drawControlPoints(Graphics2D g) {
		Point cPoint = getControlPoint();
		g.setColor(Color.RED);
		g.drawLine(cPoint.x-3, cPoint.y-2, cPoint.x+3, cPoint.y+2);// line \
		g.drawLine(cPoint.x-3, cPoint.y+2, cPoint.x+3, cPoint.y-2);// line /
		g.setColor(Color.BLACK);
	}
	
	@Override
	 public void drawZ(Graphics2D g) {
	  Point point = super.getPoint();
	  g.setFont(new Font("DialogInput", Font.PLAIN, 14));
	  g.setColor(Color.GRAY);
	  g.drawString("(z"+this.getZId()+")", point.x+15, point.y+37);
	  g.setColor(Color.BLACK);
	 }
	
	@Override
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	@Override
	public boolean contains(Point point) {
		Point selfPoint = super.getPoint();
		Rectangle rectangle = new Rectangle(selfPoint.x, selfPoint.y, 60, 40);
		return rectangle.contains(point);
	}
	public Point getControlPoint() {
		return controlPoint;
	}
	public void setControlPoint(Point controlPoint) {
		this.controlPoint = controlPoint;
	}

	@Override
	public void setPoint(Point point) {
		super.setPoint(point);
		calculateControlPoints();
	}
	
	private void calculateControlPoints() {
		Point point = super.getPoint();
		setControlPoint(new Point(point.x+30,point.y+40));
	}

	@Override
	public void cleanDraw(Graphics2D g) {
		Point point = super.getPoint();
		g.setColor(Color.WHITE);
		g.fillRoundRect(point.x, point.y, 60, 40, 10, 10);
		g.drawRoundRect(point.x, point.y, 60, 40, 10, 10);
		g.setFont(new Font("DialogInput", Font.PLAIN, 18));
		g.drawString("Start", point.x+4, point.y+22);
		
	}
	
	@Override
	public boolean haveControlPoint(Point point) {
		Point cPoint = getControlPoint();
		Rectangle rectangle = new Rectangle(cPoint.x-3, cPoint.y-2,6,4);
		if(rectangle.contains(point)){
			return true;
		}
		return false;
	}

	@Override
	public Point getControlPointByClosePoint(Point close) {
		if(haveControlPoint(close)){
			return controlPoint;
		}
		return null;
	}
	@Override
	public String toString() {
		return "Start z="+super.getZId();
	}
	@Override
	public boolean isCausePoint(Point point) {
		return haveControlPoint(point);
	}

}
